import { deletePlayWith } from "@/apis/playWith";
import DefaultTable from "@/components/DefaultTable";
import { getBreadcRumb, push } from "@/utils/util";
import { Space, Button, Popconfirm, message } from "antd";
import { ColumnsType } from 'antd/es/table'
import { useEffect, useRef } from "react";

function PlayWithManage() {
    getBreadcRumb([{ name: "陪玩列表" }])
    const TableRef = useRef<TableRefParams>(null)
    const columns: ColumnsType<BaselistItem> = [
        {
            title: "序号",
            dataIndex: "itemSn",
            render: (_text, record, index) => (((record.pageNum || 0) - 1) * (record.pageSize || 0) + index + 1)
        },
        {
            title: "陪玩编号",
            dataIndex: "playWithId",
        },
        {
            title: "陪玩名称",
            dataIndex: "playWithName",
        },
        {
            title: "单价",
            dataIndex: "unitPrice",
        },
        {
            title: "抽成",
            dataIndex: "commissionRate",
            render: (text: number) => text + "%"
        },
        {
            title: "管理类型",
            dataIndex: "mgtType",
            render: (text: string) => text == "1" ? "管理陪玩" : "普通陪玩"
        },
        {
            title: "操作",
            dataIndex: "index",
            render: (_index: any, data: any) => {
                return (
                    <Space>
                        <a onClick={() => push('/playWithList/look/' + data.playWithId)}>查看</a>
                        <a onClick={() => push('/playWithList/edit/' + data.playWithId)}>编辑</a>
                        <Popconfirm onConfirm={() => ondelBtn(data.playWithId)} title='是否要删除'>
                            <a >删除</a>
                        </Popconfirm>
                    </Space>
                );
            },
        },
    ]
    //删除
    async function ondelBtn(playWithId: string) {
        await deletePlayWith({ playWithId })
        message.success('删除成功')
        TableRef.current?.getList()
    }
    function getCreateBtn() {
        push('/playWithList/create');
    }
    useEffect(() => {
        TableRef.current?.getList()
    }, [])
    return (
        <div>
            <div className='tableWrap'>
                <Space style={{ marginBottom: '8px' }}>
                    <Button type="primary" onClick={getCreateBtn}>添加</Button>
                </Space>
                <DefaultTable columns={columns} ref={TableRef} api={'/play-with/list'} />
            </div>
        </div>
    )
}
export default PlayWithManage;
